package ru.rchervot.sanasar.client.model;

import java.util.ArrayList;


import com.google.gwt.user.client.rpc.IsSerializable;

public class SearchResults implements IsSerializable {
	
	public SearchResults() {	
	}
	
	public SearchResults(ArrayList<SearchResultsItemCandidates> results) {
		this.results = results;
	}
	
	private ArrayList<SearchResultsItemCandidates> results;

	public void setResults(ArrayList<SearchResultsItemCandidates> results) {
		this.results = results;
	}

	public ArrayList<SearchResultsItemCandidates> getResults() {
		return results;
	}

	public void setQueryID(Integer queryID) {
		this.queryID = queryID;
	}

	public Integer getQueryID() {
		return queryID;
	}

	private Integer queryID;
	
	int resultsSize;
	
	public int getResultsSize() {
		return resultsSize;
	}

	public void setResultsSize(int resultsSize) {
		this.resultsSize = resultsSize;
	}
	
	private int pageOffset;
	
	public void setPageOffset(int pageOffset) {
		this.pageOffset = pageOffset;
	}

	public int getPageOffset() {
		return pageOffset;
	}
	
	private int currentItemPosition;

	public int getCurrentItemPosition() {
		return currentItemPosition;
	}

	public void setCurrentItemPosition(int currentItemPosition) {
		this.currentItemPosition = currentItemPosition;
	}
	
	private int pageSize;

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public int getItemOffset() {
		return pageOffset * pageSize;
	}
	
	void updateNumbers() {
		pageOffsetMax = (resultsSize == 0 
				? 0 
				: ((resultsSize - 1) / pageSize));
	}
	
	private int pageOffsetMax;

	public int getPageOffsetMax() {
		return pageOffsetMax;
	}

	public void setPageOffsetMax(int pageOffsetMax) {
		this.pageOffsetMax = pageOffsetMax;
	}
	
	public void setCurrentItem(ItemObject itemObject) {
		results.get(currentItemPosition).setItemObject(itemObject);
	}
	
	public ItemObject getCurrentItem() {
		if (results == null || results.isEmpty()) {
			return null;
		} else {
			return results.get(currentItemPosition).getItemObject();
		}
	}
}
